All Questions
716 questions
-3votes
1answer
67views
Why can't I stack 3D arrays with np.concatenate in numpy, while 1D and 2D arrays work?
I'm working with 3D numpy arrays and having trouble stacking two of them. Here’s what I’m trying to do: import numpy as np grid = np.arange(16).reshape((1, 4, 4)) grid2 = grid[:, :-1, ::-1].copy() I ...
1vote
1answer
87views
How do I effectively compute pairwise quantities in numpy?
I want to compute pairwise quantities, e.g. distances between two points. A simple example would be import numpy as np N = 9 x = np.linspace(0,1,N) y = np.abs(x - x[:,None]) # pairwise 1d eucdlidian ...
1vote
2answers
740views
ValueError: could not broadcast input array from shape A into shape B
I used Python with Numpy to create an array filled with numbers from a tuple, and set it up to be a 4x4 matrix. numbers = (-8, -3, -5, 0, 4, 5, 6, 10, 7,8, 9, 100, 10, 11, 12, 1000) numbers_array = ...
0votes
1answer
41views
Why are my numpy array elements being cast to lists?
import numpy as np ar1 = np.array([[[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]]]) ar2 = np.array([[[1,2,3],[4,5,6]],[[1,2,3,4],[4,5,6,7]]]) print(ar1) print(ar2) When I run this the second array prints out ...
3votes
2answers
157views
Numpy array methods are faster than numpy functions?
I have to work with the learning history of a Keras model. This is a basic task, but I've measured the performance of the Python built-in min() function, the numpy.min() function, and the numpy ...
1vote
1answer
72views
Is there a way to efficiently construct a 3d array from symmetric submatrices of a 2d array according to an array of different index sets?
I have a two-dimensional array A, and another two-dimensional array I where each row corresponds to a set of indices with which I want to extract symmetric two-dimensional subarrays from A. I want to ...
0votes
2answers
95views
How can I multidimensionalise this code that finds indices from a list of values?
I have some code that finds the indices of elements in the "input" list that match any element in the "values" list. The indices are then outputted, arranged in the same order as ...
-1votes
1answer
93views
Manipulating a 3d array in python
I have an array called result that has a shape of (1200,67,67). Along the axis with length 1200 the array is correct. However, the other two axis have been flipped. I am getting: result[0,:,:] = array(...
1vote
1answer
728views
Difference between "size" and "itemsize" in Numpy
I have been studying for numpy library in python. I used the code import numpy as np arr=np.array([(11,12,13),(17,18,19)]) arr.size and it's output is 6 That is right but when I run import numpy as ...
0votes
0answers
49views
Chunking up a 3D array with periodic boundary conditions into subarrays
I have a 3D numpy array of shape [N,N,N]. I want to split it into subcubes of size [n,n,n] and store them in an array of shape [N_subcubes, n, n, n, 1]. I also would like each subcube to overlap the ...
0votes
1answer
126views
Mean absolute value along all columns of a 3D Numpy array
I always get find myself in state of confusion when dealing with a multi-dimensional array. Imaging having the following array of arrays, where each array contains feature importance scores (3-...
0votes
1answer
97views
Numpy comparing nested arrays
I am considering arrays of shape (n,2) for arbitrary n. I want to check whether the two-element sub-arrays match. As an example: import numpy as np a=np.array([[1,0],[2,0]]) b=np.array([[1,0],[2,0]]) ...
0votes
0answers
184views
Why is axis =2 when calculating median of every cell in each matrix in a 3D numpy array?
My task in python was to "Write a median_fits function which takes a list of FITS filenames, loads them into a NumPy array, and calculates the median image (where each pixel is the median of that ...
1vote
3answers
99views
How do I stack arrays horizontally?
I have an array: > a array([[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], [[17, 18, 19, 20], [21, 22, 23, 24], [25, 26, 27, 28], ...
1vote
3answers
68views
How do I change values in my subarrays into the avarage of those values?
I have an array: > a array([[1, 2, 3], [2, 3, 4], [3, 4, 5]]) I want to change those values to the avarage of those values, so the output will be: > a array([[2, 2, 2], [3, 3, 3], [4, 4, 4]]) ...